//
//  FCSwitchView.m
//  OilWear
//
//  Created by jjkj on 17/7/10.
//  Copyright © 2017年 jjkj. All rights reserved.
//

#import "FCSwitchView.h"
#import "UIColor+Hex.h"

@implementation FCSwitchView
-(void)awakeFromNib {
    [super awakeFromNib];
     [self setFrame:CGRectMake(0, 64, kScreenWidth, 50)];
    //[self setUpSwitchButtonAppreace:self.selectedIndex];
}
//按钮切换操作
- (IBAction)switchAction:(UIButton *)sender {
    
    //sender.selected = !sender.selected;
    NSInteger index = sender.tag - 100;
    [self setUpSwitchButtonAppreace:index];
    
    if (self.switchActionBlock) {
        self.switchActionBlock(sender.tag);
    }
}

- (void)setUpSwitchButtonAppreace:(NSInteger)index {
    
    if (0 == index) {
        
        self.firstChooseBtn.selected = YES;
        self.secondChooseBtn.selected = NO;
        
    }else {
        self.firstChooseBtn.selected = NO;
        self.secondChooseBtn.selected = YES;
    }
    
    [self setButtonAppreace:self.firstChooseBtn];
    [self setButtonAppreace:self.secondChooseBtn];
}

- (void)setButtonAppreace:(UIButton *)sender {
    
    if (YES == sender.selected) {
        //[sender setBackgroundColor:[UIColor colorWithHexString:@"0DA9D7"]];
        [sender setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [sender setTitleColor:[UIColor whiteColor] forState:(UIControlStateSelected)];
        [sender setBackgroundColor:[UIColor colorWithHexString:@"#1395CE"]];
        
        
    }else {
        // [sender setBackgroundColor:[UIColor whiteColor]];
        [sender setTitleColor:[UIColor colorWithHexString:@"#1395CE"] forState:(UIControlStateSelected )];
        [sender setTitleColor:[UIColor colorWithHexString:@"#1395CE"] forState:(UIControlStateNormal )];
        [sender setBackgroundColor:[UIColor colorWithHexString:@"D7D7D7"]];
    }
}

- (void)setUpSwitchViewTitleWith:(NSArray *)titles {
    
    [self.firstChooseBtn setTitle:titles[0] forState:(UIControlStateNormal)];
    [self.firstChooseBtn setTitle:titles[0] forState:(UIControlStateHighlighted)];
    [self.firstChooseBtn setTitle:titles[0] forState:(UIControlStateSelected)];
    
    [self.secondChooseBtn setTitle:titles[1] forState:(UIControlStateNormal)];
    [self.secondChooseBtn setTitle:titles[1] forState:(UIControlStateHighlighted)];
    [self.secondChooseBtn setTitle:titles[1] forState:(UIControlStateSelected)];
   
}
@end
